#include "bsp_crc.h"
#include "gd32a508_crc.h"

dv_CRC32_TypeDef dv_CRC32;

static void bsp_crc_init(void)
{
    /* Enable CRC clock */
    rcu_periph_clock_enable(RCU_CRC);
}

static uint32_t bsp_crc_CalcBlockCRC(uint32_t *pBuffer, uint32_t BufferLength)
{
    uint32_t index;

    CRC_CTL |= (uint32_t)CRC_CTL_RST;

    for (index = 0U; index < BufferLength; index++)
    {
        CRC_DATA = pBuffer[index];
    }
    return (CRC_DATA);
}

void init_bsp_crc(void)
{
    dv_CRC32.finit = bsp_crc_init;
    dv_CRC32.fwrite = bsp_crc_CalcBlockCRC;
}
